package com.bw.aop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAOP {

    @Around("execution(* com.bw.controller.*.*(..))")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        System.out.println("方法名 " + joinPoint.getSignature().getName());
        // java 对象 -》 json字符串
//        System.out.println("方法入参 " + JSON.toJSONString(joinPoint.getArgs(), SerializerFeature.IgnoreNonFieldGetter));
        System.out.println("方法入参 " + joinPoint.getArgs());
        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long l2 = System.currentTimeMillis();
        System.out.println("方法耗时 " + (l2 - l));
        System.out.println("方法的返回值 " + JSON.toJSONString(proceed));
        return proceed;


    }
}
